package hzau.controller;

import hzau.dao.SelectionQuestionDao;
import hzau.pojo.question.Question;
import hzau.pojo.question.SelectionQuestion;
import hzau.pojo.requestParams.CollegeRegisterParam;
import hzau.pojo.requestParams.QuestionsRegisterParam;
import hzau.pojo.requestParams.SelectionQuestionParam;
import hzau.result.Result;
import hzau.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@CrossOrigin
@RestController
@RequestMapping("question")
@Api(tags = "试题相关接口")
public class QuestionController {
    @Autowired
    QuestionService questionService;
    @PostMapping("register/question")
    @ApiOperation("新增非选择题题")
    public Result register(@RequestBody QuestionsRegisterParam question){
        return questionService.register(question);
    }
    @PostMapping("register/selectedQuestion")
    @ApiOperation("新增选择题")
    public Result registerSelectedQuestion(@RequestBody SelectionQuestionParam question){
        return questionService.registerSelectedQuestion(question);
    }
    @GetMapping("getOne/Question/{id}")
    @ApiOperation("查询一个非选择题")
    public Result getOneQuestion(@PathVariable Long id){
        return questionService.getOneQuestion(id);
    }
    @GetMapping("getOne/SelectionQuestion/{id}")
    @ApiOperation("查询一个选择题")
    public Result getOneSelectionQuestion(@PathVariable Long id){
        return questionService.getOneSelectionQuestion(id);
    }
    @GetMapping("getAll/Question/{id}")
    @ApiOperation("查询一张试卷的所有非选择题")
    public Result getAllQuestion(@PathVariable Long id){
        return questionService.getAllQuestion(id);
    }
    @GetMapping("getAll/SelectionQuestion/{id}")
    @ApiOperation("查询一张试卷的所有选择题")
    public Result getAllSelectionQuestion(@PathVariable Long id){
        return questionService.getAllSelectionQuestion(id);
    }
    @PostMapping("update/SelectionQuestion")
    @ApiOperation("更新选择试题")
    public Result updateSelectionQuestion(@RequestBody SelectionQuestion question){
        return questionService.updateSelectionQuestion(question);
    }
    @PostMapping("update/Question")
    @ApiOperation("更新非选择试题")
    public Result updateQuestion(@RequestBody Question question){
        return questionService.updateQuestion(question);
    }
    @DeleteMapping("delete/Question")
    @ApiOperation("删除非选择试题")
    public Result deleteQuestion(@RequestBody Question question){
        return questionService.deleteQuestion(question);
    }
    @DeleteMapping("delete/SelectionQuestion")
    @ApiOperation("删除选择试题")
    public Result deleteSelectionQuestion(@RequestBody SelectionQuestion question){
        return questionService.deleteSelectionQuestion(question);
    }
    @GetMapping("get/Quesetion/{type}/{paperId}")
    @ApiOperation("查询一张试卷的某种题型")
    public Result getOneKindQuestion(@PathVariable Integer type,@PathVariable Long paperId){
        return  questionService.getOneKindQuestion(type,paperId);
    }
    @PostMapping("registerOrUpdateQuestion/selectedQuestion")
    @ApiOperation("新增或者更新选择试题")
    public Result registerOrUpdateSelectionQuestion(@RequestBody SelectionQuestion question){
        return  questionService.registerOrUpdateselecteQuestion(question);
    }
    @PostMapping("registerOrUpdateQuestion/Question")
    @ApiOperation("新增或者更新非选择试题")
    public Result registerOrUpdateQuestion(@RequestBody Question question){
        return  questionService.registerOrUpdateQuestion(question);
    }
    @GetMapping("getOne/SelectionQuestion/selectByPaperAndId/{paperId}/{id}")
    @ApiOperation("根据试卷id和题号查询一个选择题")
    public Result selectByPaperAndId(@PathVariable Long paperId,@PathVariable Integer id){
        return questionService.selectByPaperAndId(paperId,id);
    }
    @GetMapping("getOne/Question/selectByPaperAndId/{paperId}/{type}/{id}")
    @ApiOperation("根据试卷id和题号查询一个非选择题选择题")
    public Result selectQuestionByPaperAndId(@PathVariable Long paperId,@PathVariable Short type,@PathVariable Integer id){
        return questionService.selectQuestionByPaperAndId(paperId,type,id);
    }
    @GetMapping("getAll/Questions/selectByPaperAndId/{paperId}/{type}")
    @ApiOperation("根据试卷id查询一个非选择题选择题")
    public Result selectQuestionsByPaperAndId(@PathVariable Long paperId,@PathVariable Short type){
        return questionService.selectQuestionsByPaperAndId(paperId,type);
    }
    @GetMapping("get/getSelectionNumber/{paperId}")
    @ApiOperation("查询已经出的选择题数量")
    public Result getSelectionNumber(@PathVariable Long paperId){
        return questionService.getSelectionNumber(paperId);

    }
    @GetMapping("get/getQuestionNumber/{paperId}/{type}")
    @ApiOperation("查询已经出的问题数量")
    public Result getQuestionNumber(@PathVariable Long paperId,@PathVariable Short type){
        return questionService.getQuestionNumber(paperId,type);

    }
    @PostMapping("get/getSelectionScore")
    @ApiOperation("查询选择题相似度最高的5道题")
    public Result getSelectionScore(String description) throws IOException {
        return questionService.getSelectionScore(description);

    }
    @PostMapping("get/getQuestionScore")
    @ApiOperation("查询选择题相似度最高的5道题")
    public Result getQuestionScore(String description) throws IOException {
        return questionService.getQuestionScore(description);

    }

}
